The Device Event Controller (attached to Gameboard) exposes all the companion device features available to creators. This controller primarily lets Creators show system popups and reset the Play panel on the Companion app.

Video Walkthrough:

Step-by-Step

The Gameboard prefab is always available in your game as long as the SDK has been integrated. In order to access it from our custom Mono Behavior we just need to find it by its tag.

    GameObject gameboardObject = GameObject.FindWithTag("Gameboard");

With access to our Gameboard object we can then move on to obtain a reference to the Drawer Controller. This controller allow us to perform certain operations on Companion like clearing the play panel, and displaying messages to the user.

We will first need to define a reference to the controller to make it available throughout our script:

     DeviceEventController deviceEventController;

We can no proceed to request the controller from the Gameboard object.

     GameObject gameboardObject = GameObject.FindWithTag("Gameboard");
     deviceEventController = gameboardObject.GetComponent<DeviceEventController>();

To display a pop up message on "userABC"'s companion with the message "POP" that will remain on the screen for 3 seconds we do the following:

    // Display a pop up message on Companion of userABC with the text "POP" for 3 seconds.
    await deviceEventController.DisplaySystemPopup("userABC", "POP", 3.0f);

An alert dialog is a prompt that has a title and content along with buttons. The dialog will be removed after pressing any of the buttons, and a CompanionButtonPressed event will be sent. See Companion Button Controller for more information on setting up the event listener.

To display a dialog message on "userABC"'s companion with the message "Press button to continue" that will have a default single button that says "OK"

    deviceEventController.DisplayAlertDialog("userABC", new DisplayAlertDialog
        {
            title = "Alert Dialog Title",
            content = "Press button to continue"
        });

Step-by-Step

To programatically hide the alert dialog you can send null instead of a display alert dialog object.

    deviceEventController.DisplayAlertDialog("userABC", null);

This shows an alert with 2 buttons and some color customization.

    deviceEventController.DisplayAlertDialog("userABC", new DisplayAlertDialog()
        {
            title = "Alert Dialog Title",
            content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eget risus nec sapien blandit gravida non at dui...",
            fontColor = "red",
            buttons = new EventArgSetCompanionButton[] {
                new EventArgSetCompanionButton () {
                    buttonId = "noDialog",
                    buttonText = "No",
                }, new EventArgSetCompanionButton () {
                    buttonId = "yesDialog",
                    buttonText = "Yes",
                }
            }
        });

Step-by-Step

Display Alert Dialog Properties

At times it might be necesary for the game to clear the content of the Play component to layout some new content.

To reset the play panel on "userABC"'s companion we do the following:

    // Reset all the content of the Play Panel of userABC.
    await deviceEventController.ResetPlayPanel("userABC");

For times when we want to call a player's attention to companion we can also request companion to vibrate like so:

    // Vibrate the first companion user's device
    await deviceEventController.VibrateCompanionDevice("userABC");

You can also send a specific pattern of vibration, specifying how long to wait between vibrations. This example below would result in the following pattern: 100ms pause, 400ms vibration, 1000ms pause, 400ms vibration, 100ms pause, 400ms vibration.

deviceEventController.VibrateCompanionDevice("userABC", new uint[] { 100, 1000, 100});

This section include the entire code in one single, easy to copy section.

     DeviceEventController deviceEventController;

    // Start is called before the first frame update
    void Start()
    {
        GameObject gameboardObject = GameObject.FindWithTag("Gameboard");
        deviceEventController = gameboardObject.GetComponent<DeviceEventController>();
    }